using Cysharp.Threading.Tasks;
using QFramework;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnterGameState : AbstractState<LaunchState, Launch>, IController
{
    private float durationTime = 0;
    public EnterGameState(FSM<LaunchState> fsm, Launch target): base(fsm, target)
    {

    }

    public override void OnEnter()
    {
        UpdateAgvInfo(RequestUrl.intervalTime);
        UpdateWmsInfo(RequestUrl.intervalTime);
    }
    protected override void OnUpdate()
    {
        //UpdateAgvInfo();
    }
    private async void UpdateAgvInfo(float intervalTime)
    {
        //while (this != null)
        {
            this.SendCommand(new UpdateAgvInfoCommand());
            await UniTask.Delay(System.TimeSpan.FromSeconds(intervalTime));
        }
    }
    private async void UpdateWmsInfo(float intervalTime)
    {
        //while (this != null)
        {

            this.SendCommand(new UpdateStorageInfoCommand());
            await UniTask.Delay(System.TimeSpan.FromSeconds(intervalTime));
        }
    }
    private void UpdateWmsInfo()
    {
        this.SendCommand(new UpdateStorageInfoCommand());
    }
    private void UpdateAgvInfo()
    {
        durationTime += Time.deltaTime;
        if (durationTime >= RequestUrl.intervalTime)
        {
            this.SendCommand(new UpdateAgvInfoCommand());
            durationTime -= RequestUrl.intervalTime;
        }
    }
    public IArchitecture GetArchitecture()
    {
        return DigitalTwin_GeLinMei_2.Interface;
    }
}
